<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>
<%@taglib prefix="code" tagdir="/WEB-INF/tags"%>
 
<div style="margin:20px 0;"></div>
<div class="easyui-panel">
	<div style="padding:10px 60px 20px 60px">
		<form id="pushMesageForm"  name="pushMesageForm" method="post" action="<c:url value='/messageInf/savePushMessageDetail.do'/>">
			<input type="hidden" id="message_uuid" name="message_uuid" value="${infEntity.message_uuid}"/>
			<input type="hidden" id="rec_id" name="rec_id" value="${infEntity.rec_id}"/>
			<table cellpadding="5" style="width:100%">
				<tr>
					<td>发送类型:</td>
					<td><code:codeSelect id="send_message_type" name="send_message_type"  code_type="SEND_MESSAGE_TYPE" selectId="${infEntity.send_message_type}"></code:codeSelect></td>
				</tr>

				<tr >
					<td id = "labelName">会员名称:</td>
					<td id = "login">
						<input class="easyui-textbox"  type="text" readonly="readonly" id="login_name"  name="custom_name"  value="${infEntity.custom_name}"/>
						<a href="javascript:void(0)" class="easyui-linkbutton detail-remove" iconCls="icon-search" id="selelctBtn" >选择</a>
						<input   type="hidden"  id="custom_uuid" name="custom_uuid" value="${custom_uuid}"/>
					</td>

					<td id = "ins">
						<input  type="text"  id="inst_name" readonly="readonly" name="name"  data-options="validType:['length[0,120]']" value="${infEntity.name}"></input>
						<a href="javascript:void(0)" class="easyui-linkbutton detail-remove" iconCls="icon-search" id="selelctInsBtn" >选择</a>
						<input    type="hidden" id="ins_uuid" name="ins_uuid" value="${ins_uuid}"/>
					</td>
				</tr>

				<tr >
					<td>标题:</td>
					<td><input class="easyui-textbox" type="text"  name="message_title" data-options="required:true,validType:['length[0,120]']" value="${infEntity.message_title}"></input></td>
				</tr>
				<tr>
					<td >内容:</td>
					<td><input class="easyui-textbox" name="message_content" style="height:200px;width:400px"  data-options="required:true,multiline:true,validType:['length[0,200]']" value="${infEntity.message_content}"/></td>
				</tr>
			</table>
			<div style="text-align:center;padding:5px">
				<a href="javascript:void(0)" class="easyui-linkbutton btn detail-remove" iconCls="icon-save" onclick="submitForm('pushMesageForm')">保存</a>
				<a href="javascript:void(0)" class="easyui-linkbutton btn" iconCls="icon-back" onclick="back()">返回</a>
			</div>
		</form>
	</div>
</div>

<div id="menuTree">
	<div id="ztreeObj" class="ztree"></div>
</div>
<script>
		
		$('#send_message_type').combobox({
			onSelect: function(record){
				chg(record);
			}
		});
		function chg(record){
			var recodVal = record.id;
			changeLabel(recodVal);
		}
		function changeLabel(recodVal){
			  if(recodVal=="1"){
		    	$("#ins").attr("style", "display: block;");
		    	$("#login").hide();//.attr("style", "display: none;");
		        $("#labelName").html("所属机构");
		        $("#inst_name").attr("class", "easyui-textbox");
		        $.parser.parse($("#ins"));
		   
		     }else{
		     	$("#ins").hide();//.attr("style", "display: none;");
		    	$("#login").attr("style", "display: block;");
		        $("#labelName").html("会员名称");
		       
		     }
		}
		
        var ztreeObj;
       /* /!*选择按钮*!/*/
        $("#selelctBtn").click(function(){
            ztreeObj = showAppTree(selected, $("#custom_uuid").val());
        });
       /* /!*确定按钮回调*!/*/
        function selected(){
            var nodes = ztreeObj.getSelectedNodes();
            console.log(nodes);
            if(nodes && nodes.length > 0){
                $("#login_name").textbox("setValue", nodes[0].NAME);
                $("#custom_uuid").val(nodes[0].ID);
            }
        }
        function showAppTree(confirmCallback, uuid, option){
            var options = {
                url: "../messageInf/customerTree_show.do",
                title: "会员树查看",
                confirmCallback: confirmCallback,
                openIds: uuid,
                showSearch: true,
                searchTitle: "手机号/名称/编号"
            };
            options = $.extend({}, options, option);
            return showTree(options);
        }
        function showTree(options){
            var jpTree = $().jpTree(options);
            return jpTree;
        }


     var ztreeIns;
    /*/!*选择按钮*!/*/
    $("#selelctInsBtn").click(function(){
        ztreeIns = showInsAppTree(selectInsed, $("#ins_uuid").val());
    });
   /* /!*确定按钮回调*!/*/
    function selectInsed(){
        var nodes = ztreeIns.getSelectedNodes();
        console.log(nodes);
        if(nodes && nodes.length > 0){
            $("#ins_uuid").textbox("setValue", nodes[0].ID);
            $("#inst_name").textbox("setValue", nodes[0].NAME);
            $("#ins_app_uuid").val(nodes[0].INSUUID);
            $("#ins_uuid").val(nodes[0].ID);
        }
    }
    function showInsAppTree(confirmCallback, uuid, option){
        var options = {
            url: "../organization/getAppInfTree.do",
            title: "选择机构",
            confirmCallback: confirmCallback,
            openIds: uuid,
            showSearch: true,
            searchTitle: "机构代码/名称"
        };
        options = $.extend({}, options, option);
        return showInsTree(options);
    }
    function showInsTree(options){
        var jpTree = $().jpTree(options);
        return jpTree;
    }

 
      /*  $(function(){
           $("#send_message_type").combobox({
               onSelect: function(record){
                   if(document.getElementById("send_message_type").value=="1"){
                       document.getElementById("login").style.display="block";
                       document.getElementById("inst").style.display="none";
                   }else{
                       document.getElementById("login").style.display="none";
                       document.getElementById("inst").style.display="block";
                   }
               }
           });
       });*/
       
       $(document).ready(function() { 
    	   var rec_id = $("#rec_id").val();
    	   if(rec_id &&  rec_id != null &&  rec_id != ""){
    		   var custom_uuid = $("#login_name").val();
        	   if(custom_uuid && custom_uuid !=null && custom_uuid != ""&& custom_uuid != "-"){
        		   $("#send_message_type").combobox('select', '0');
        		   changeLabel("0");
                   document.getElementById("selelctBtn").style.display="none";
        	   }else{
        		   $("#send_message_type").combobox('select', '1');
        		   changeLabel("1");
                   document.getElementById("selelctInsBtn").style.display="none";
        	   }
    	   }
       });
    
</script>